<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<html>
  <head>
    <base href="<%=basePath%>">
      <meta charset="UTF-8">
    <title>员工信息表</title>
	<meta name="pragma" content="no-cache">
	<meta name="cache-control" content="no-cache">
	<meta name="expires" content="0">
      <link href="../../../../static/easyui/themes/insdep/easyui.css" rel="stylesheet" type="text/css">
      <link href="../../../../static/easyui/themes/insdep/easyui_animation.css" rel="stylesheet" type="text/css">
      <link href="../../../../static/easyui/themes/insdep/easyui_plus.css" rel="stylesheet" type="text/css">
      <link href="../../../../static/easyui/themes/insdep/insdep_theme_default.css" rel="stylesheet" type="text/css">
      <link href="../../../../static/easyui/themes/insdep/icon.css" rel="stylesheet" type="text/css">
      <link href="../../../../static/easyui/themes/color.css" rel="stylesheet" type="text/css">

      <link href="../../../../static/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" >
      <link href="../../../../static/css/common.css" rel="stylesheet" type="text/css" >

      <script type="text/javascript" src="../../../../static/jquery/jquery.min.js"></script>
      <script type="text/javascript" src="../../../../static/easyui/jquery.easyui.min.js"></script>
      <script type="text/javascript" src="../../../../static/easyui/themes/insdep/jquery.insdep-extend.min.js"></script>
      <script type="text/javascript" src="../../../../static/ztree/jquery.ztree.all.min.js"></script>
      <script type="text/javascript" src="../../../../static/easyui/easyui-lang-zh_CN.js"></script>
      <script type="text/javascript" src="../../../../static/kindeditor/kindeditor-all-min.js"></script>

  </head>
  <style type="text/css">
  body{
  	font-size:14px
  }
  </style>
  <body >
    <div id="toolbar" style="padding:0 30px;">
      <form action=""></form>
       	<b>员工姓名: </b><input class="easyui-textbox" id="name" type="text" name="name" style="width:166px;height:35px;line-height:35px;"/>
        <a href="javascript:void(0);" id="searchBtn" class="easyui-linkbutton" iconCls="icon-search" data-options="selected:true" style="background-color:#00aa00;color:white">查询</a>
        <a href="javascript:void(0);" id="setBtn" class="easyui-linkbutton" iconCls="icon-reload" style="background-color:#00aa00;color:white;margin-left:10px">重置</a>
        <a href="javascript:void(0);" onclick="return add('/toAddEmployee')" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="background-color:#00aa00;color:white;margin-left:10px">添加</a>
    	<a href="javascript:void(0);" onclick="return remove('/toDeleteEmployee')" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" style="background-color:#f00;color:white;margin-left:10px">删除</a>
    	<a href="javascript:void(0);" onclick="return edit('/toEditEmployee')" id="editBtn" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" style="background-color:#00aa00;color:white;margin-left:10px">修改</a>
    </div>
    <table id="empList" class="easyui-datagrid" style="font-size:14px"></table>
    <script type="text/javascript">
    	// 为查询按钮添加处理函数
	    $("#searchBtn").on("click",function(){
          var na = $("#name").val();
          $("#empList").datagrid({
            // 拼接值的方式将查询条件传去后台
            url : "/listEmployee?name="+na,
            pagination : true,
            toolbar : "#toolbar",
            fitColumns : true,
            idField : "empid",
            rownumbers : true,
            // singleSelect:true,
            columns : [
              [
                {field:"empid",title:"选择",checkbox:true},
                {field:"name",title:"员工姓名",sortable:true,width:10},
                {field:"telephone",title:"联系电话",sortable:true,width:10},
                {field:"email",title:"邮箱",sortable:true,width:10},
                {field:"address",title:"地址",width:10},
              ]
            ],
            loadFilter: function (data) {
              return {"total": data.total, "rows": data.rows};
            }
          });
		})

		//为添加按钮添加事件处理函数
		function add(url){
          window.location.href=url
    		// parent.openTopWindow({
    		// 	title:"添加员工信息",
    		// 	width:550,
    		// 	height:500,
    		// 	"url": url,
    		// 	close : function(){
    		// 		$("#empList").datagrid("reload");
    		// 	}
    		// });
    	}


       //为重置按钮添加事件处理函数
         $("#setBtn").on("click",function(){
              $("#empList").datagrid("load",{"emp.name":""});
         })
  
    	//修改按钮事件处理函数
      	function edit(url){
    		var rows = $("#empList").datagrid("getChecked");
    		if(!rows.length){
    			$.messager.alert("提示","请选择需要修改的权限信息");
    			return false;
    		}
    		
    		if(rows.length >= 2){
    			$.messager.alert("提示","一次只能选择修改一位员工的信息");
    			return false;
    		}
    		
    		var empId = rows[0].id;
          window.location.href=url+"?id="+empId
    		// parent.openTopWindow({
    		// 	title:"修改员工信息",
    		// 	width:550,
    		// 	height:500,
    		// 	"url" : url+"?id="+empId,
    		// 	close : function(){
    		// 		$("#empList").datagrid("reload");
    		// 	}
    		// });
    	}
    	
        //删除按钮事件处理函数
        function remove(url){
        	//获取到选中的一行数据
    			var rows = $("#empList").datagrid("getChecked");
    			
    			if(!rows.length){
    				$.messager.alert("警告","请选择要删除的数据");
    				return;
    			}

          $.messager.confirm("警告","数据删除无法恢复",function(b){
            if(b){
              var ids=new Array();
              $.each(rows,function(index,obj){
                ids.push(obj.id)
              })
              ids=ids.join(",")
              $.post(url,
                      {"ids":ids},
                      function(data){
                        if(data.success && data){
                          $.messager.alert("提示",data.message)
                          $("#empList").datagrid("reload");
                          return;
                        }
                        $.messager.alert("提示",data.message)
                      }, "json")
            }
          })
        }
    	//加载用户数据
    	$(function(){
    		$("#empList").datagrid({
    			url : "/listEmployee",
    			pagination : true,
    			toolbar : "#toolbar",
    			fitColumns : true,
    			idField : "empid",
    			rownumbers : true,
    			// singleSelect:true,
    			columns : [
                    [
    				{field:"empid",title:"选择",checkbox:true},
    				{field:"name",title:"员工姓名",sortable:true,width:10},
    				{field:"telephone",title:"联系电话",sortable:true,width:10},
    				{field:"email",title:"邮箱",sortable:true,width:10},
    				{field:"address",title:"地址",width:10},
                ]
                ],
              loadFilter: function (data) {
                return {"total": data.total, "rows": data.rows};
              }
    		});
    	});
    </script>
  </body>
</html>
